const {app,BrowserWindow,ipcMain,Menu,globalShortcut} = require('electron')
const path = require('path')
 // 热加载
// try {
//   require('electron-reloader')(module,{});
// } catch (err) {
//     console.log(err)
// }

let mainwindow = null
//取消小菜单
Menu.setApplicationMenu(null)

function mainWndow(){
    let window = new BrowserWindow({
        width:350,
        height:600,
        webPreferences:{
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule:true,
            preload:path.resolve(__dirname,'./preload.js')
        }
    })
    window.loadURL(app.isPackaged //判断是否打包
        ?path.resolve(__dirname,'../vue-dist/index.html')
        :'http://localhost:3077/#/')
    window.webContents.openDevTools()

    return window
}


ipcMain.on('join',(event,arg)=>{
    event.reply('joinReply','主进程回复join事件')
})
ipcMain.on('skip',(event,arg)=>{
    if(arg === 'chatPage'){
        mainwindow.setSize(700,600)
    }else if(arg === 'userRole'){
        mainwindow.setSize(350,600)
    }
})


app.on('ready',()=>{
    globalShortcut.register('ctrl+k',()=>{
        BrowserWindow.getFocusedWindow().webContents.openDevTools()
    })
    mainwindow = mainWndow()
})

